Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

19.5 Enabling Initialization Call Event Tracing

An initialization call (initcall) is a highly sophisticated automated mechanism built into the Linux kernel. It empowers the kernel to automatically execute initialization functions across various device drivers and subsystems in a predefined priority sequence without explicitly invoking each of them one by one. The inner mechanics of the initcall architecture will be covered comprehensively in subsequent chapters.

The primary objective of the function trace_initcall_start_cb() is to activate real-time tracking monitoring the execution time spent by each individual initialization function. When the system boot command line (cmdline) incorporates the parameter initcall_debug, if tracepoints are compiled out of the image (TRACEPOINTS_ENABLED is disabled), this function resolves to a no-operation (no-op) block and executes no logic.

Conversely, if tracepoint debugging is active in the image, the routine initcall_debug_enable() invokes register_trace_initcall_start() to bind a callback handler named trace_initcall_start_cb onto the initcall_start tracepoint (hook), while passing the memory address of the tracking variable initcall_calltime down to the callback. When the kernel execution flow reaches do_initcall to invoke a specific initcall, it triggers the internal wrapper trace_initcall_start() (functionally identical to do_trace_initcall_start). If a callback hook is registered at this checkpoint, the execution path branches to process the hook—recording the current timestamp or emitting debug logs—before returning to resume the original initialization task. The initcall_calltime variable is leveraged to archive the precise start time of the initialization function.

Upon registering the leading callback handler trace_initcall_start_cb(), initcall_debug_enable() calls register_trace_initcall_finish to bind a corresponding termination callback handler named trace_initcall_finish_cb onto the initcall_finish completion tracepoint (hook) to log the end time of that explicit initcall. When an individual initialization function concludes, it triggers trace_initcall_finish() (functionally identical to do_trace_initcall_finish). By subtracting the recorded start time from this newly captured end time, the subsystem computes the exact duration consumed by that specific initialization routine.

The low-level function routine responsible for executing an individual initcall is implemented as:

int __init_or_module do_one_initcall(initcall_t fn)
{
	do_trace_initcall_start(fn);     	 /* Tracepoint hook: Start timing */
	ret = fn();                    		/* Execute the real init routine (e.g., driver probe) */
	do_trace_initcall_finish(fn, ret); 	/* Tracepoint hook: Terminate timing */
}

If register_trace_initcall_start is conceptually equivalent to clicking a stopwatch to start timing, then register_trace_initcall_finish represents clicking it again to freeze the timer and log the finalized performance score.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com